package com.lwg.datastructure.greedy;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @FileName: PointsOfBiscuits.java
 * @Description: 分饼干
 * Copyright: Copyright(C) 2020-2022
 * Company  : Sunyard.hangzhou
 * @author: 李炜光
 * @slogan:
 * @Date: 2022/2/14 0014
 */
public class PointsOfBiscuits {

    public static void main(String[] args) {
        PointsOfBiscuits pointsOfBiscuits = new PointsOfBiscuits();
        System.out.println(pointsOfBiscuits.findMaxSum());
    }

    //依次表示为孩子的数量，孩子的胃口数量，饼干的数量，饼干的每个尺寸
    public int findMaxSum() {
        int N = 0;
        int M = 0;
        Scanner in = new Scanner(System.in);
        //while (in.hasNextLine()) {
        N = in.nextInt();    //孩子的数量
        int[] g = new int[N];   //孩子的胃口

        for (int i = 0; i < N; i++) {
            g[i] = in.nextInt();
        }
        Arrays.sort(g);
        M = in.nextInt();    //饼干的数量
        int[] s = new int[M];   //饼干的尺寸

        for (int j = 0; j < M; j++) {
            s[j] = in.nextInt();
        }
        Arrays.sort(s);
        //break;
        //}

        int count = 0;  //记录满足的最多孩子数量
        for (int i = 0, j = 0; i < N && j < M; i++, j++) {
            while (j < M && g[i] > s[j]) {
                j++;
            }
            if (j < M) {
                count++;
            }
        }
        return count;
    }
}